# coding:utf-8
import sys;
import urllib;
import urllib2;
import cookielib;
import codecs;
import datetime;
import poster;
from poster.encode import multipart_encode;
from poster.streaminghttp import register_openers, StreamingHTTPHandler, StreamingHTTPRedirectHandler, StreamingHTTPSHandler;

register_openers();

if(__name__ == "__main__"):
    
    
    
    '代理'
    """
    poxy = urllib2.ProxyHandler({'http':"http://xxx.com:xxx"});
    opener = urllib2.build_opener(poxy,urllib2.HTTPHandler); #'(urllib2.HTTPHandler(poxy));'
    
    urllib2.install_opener(opener);
    """
    
    """
    
    'cookie'
    cc = cookielib.CookieJar(); #cookielib.LWPCookieJar();    
    opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cc));
    
    urllib2.install_opener(opener);
    
    request = urllib2.Request("http://www.baidu.com");
    
    response = urllib2.urlopen(request);
    
    print cc;    
    
    """
   
    print datetime.datetime.today().strftime("%Y-%m-%d %H:%M:%S");
    
    params = {'name':'t.img', 'image':open('/home/kelly/sourceImage/11ww.img', 'rb')};
    
    datagen, headers = poster.encode.multipart_encode(params);    
    
    request = urllib2.Request("http://192.168.10.192:8001/upload", datagen, headers);    
    
    response = urllib2.urlopen(request);
    
    m_str_return = response.read();
    
    print m_str_return; 
    
    print datetime.datetime.today().strftime("%Y-%m-%d %H:%M:%S");
    
    pass
